package com.集合.Map___;

import java.util.*;

@SuppressWarnings("all")
public class Map接口特点2 {
    public static void main(String[] args) {
        /**
         * 8.为了方便遍历，提供了Set set = hashMap.entrySet()的方法，返回Set集合，里面存放Node对象；Node里存放k-v
         * 9.Set set = hashMap.keySet()   返回存放所有key元素的set集合
         * 9.Set set = hashMap.values()   返回存放所有value元素的Collection集合
          */
        HashMap hashMap = new HashMap();
        hashMap.put(1,1);
        hashMap.put(2,1);
        hashMap.put(3,1);
        hashMap.put(4,1);

        Set set = hashMap.entrySet();
        for (Object o :set) {
            Map.Entry entry = (Map.Entry)o;//向下转型成Entry类型；调用其方法得到K和V；
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
//        Set set1 = hashMap.keySet();
//       Collection set2 = hashMap.values();
    }
}
